﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace XtremBiking.Logica
{
    internal static class Extensions
    {

        #region Encrypt
        /// <summary>
        /// Method responsible to encrypt a plain text receibed by parameter
        /// </summary>
        /// <param name="textToEncrypt">Text to encrypt</param>
        /// <returns>Encrypted text</returns>
        public static string Encrypt(this string textToEncrypt)
        {

            string CryptText;

            using (HashAlgorithm hashAlg = HashAlgorithm.Create("SHA256"))
            {
                byte[] pwordData = Encoding.Default.GetBytes(textToEncrypt);
                byte[] hash = hashAlg.ComputeHash(pwordData);
                CryptText = BitConverter.ToString(hash);
            }

            return CryptText;
        }
        #endregion

    }
}
